using System.Linq.Expressions;
using FastNetCore.Core.Options;
using SqlSugar;

namespace FastNetCore.Core.Interfaces.DAO;

/// <summary>
/// 数据层基接口
/// </summary>
/// <typeparam name="BaseEntity">实体需要继承于BaseEntity</typeparam>
public interface IBaseRepository<BaseEntity>:IDbSetter
{
    DBExecResult Add(BaseEntity entity);
    
    Task<DBExecResult> AddAsync(BaseEntity entity);
    
    DBExecResult BatchAdd(List<BaseEntity> entities);
    
    Task<DBExecResult> BatchAddAsync(List<BaseEntity> entities);
    
    DBExecResult Update(BaseEntity entity);
    
    Task<DBExecResult> UpdateAsync(BaseEntity entity);
    
    DBExecResult BatchUpdate(List<BaseEntity> entities);
    
    Task<DBExecResult> BatchUpdateAsync(List<BaseEntity> entities);
    
    DBExecResult Delete(BaseEntity entity);
    
    Task<DBExecResult> DeleteAsync(BaseEntity entity);
    
    DBExecResult BatchDelete(List<BaseEntity> entities);
    
    Task<DBExecResult> BatchDeleteAsync(List<BaseEntity> entities);
    
    /// <summary>
    /// 更新保存，先更新，如果不存在保存
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    DBExecResult Save(BaseEntity entity);
    
    /// <summary>
    /// 异步更新保存，先更新，如果不存在保存
    /// </summary>
    /// <param name="entity"></param>
    /// <returns></returns>
    Task<DBExecResult> SaveAsync(BaseEntity entity);
    
    DBExecResult<BaseEntity> GetOne(Expression<Func<BaseEntity, bool>> predicate);
    
    Task<DBExecResult<BaseEntity>> GetOneAsync(Expression<Func<BaseEntity, bool>> predicate);
    
    DBExecResult<BaseEntity> GetOneById(long id);
    
    Task<DBExecResult<BaseEntity>> GetOneByIdAsync(long id);
    
    DBExecResult<List<BaseEntity>> GetAll();
    
    Task<DBExecResult<List<BaseEntity>>> GetAllAsync();
    
    DBExecResult<List<BaseEntity>> GetAll(Expression<Func<BaseEntity, bool>> predicate);
    
    Task<DBExecResult<List<BaseEntity>>> GetAllAsync(Expression<Func<BaseEntity, bool>> predicate);
    
    DBExecResult<List<BaseEntity>> GetPage(int pageIndex,int pageSize,ref int total);
    
    Task<DBExecResult<List<BaseEntity>>> GetPageAsync(int pageIndex,int pageSize,RefAsync<int> total);
    
    DBExecResult<List<BaseEntity>> GetPage(int pageIndex,int pageSize,Expression<Func<BaseEntity, bool>> predicate,ref int total);
    
    Task<DBExecResult<List<BaseEntity>>> GetPageAsync(int pageIndex,int pageSize,Expression<Func<BaseEntity, bool>> predicate,RefAsync<int> total);
    
    int Count();
    
    Task<int> CountAsync();
    
    int Count(Expression<Func<BaseEntity, bool>> predicate);
    
    Task<int> CountAsync(Expression<Func<BaseEntity, bool>> predicate);
}